simple mathematical functions, mostly templated
|
|
template<typename T > |
| const T & | max (const T &a, const T &b) |
| | maximum of 2 values
|
| |
|
template<typename T > |
| const T & | min (const T &a, const T &b) |
| | minimum of 2 values
|
| |
|
template<typename T > |
| const T & | constrain (T &x, const T &a, const T &b) |
| |
|
template<typename T > |
| const T & | max (const T &a, const T &b, const T &c) |
| | maximum of three arguments
|
| |
|
template<typename T > |
| const T & | min (const T &a, const T &b, const T &c) |
| | minimum of three arguments
|
| |
|
template<typename T > |
| int | sign (const T &a) |
| | the sign of a number
|
| |
|
template<typename T > |
| T | sqr (const T &a) |
| | square of a number
|
| |
|
template<typename T > |
| T | cub (const T &a) |
| | cube of a number
|
| |
|
template<typename T > |
| T | quad (const T &a) |
| | fourth power of a number
|
| |
|
template<typename T > |
| T | powerN (const T &a, unsigned int n) |
| | power of a by positive integer exponent n
|
| |
|
template<typename T > |
| T | power (const T &a, const int n) |
| | power of by integer exponent n
|
| |
|
template<typename T > |
| T | nextPowerOf2 (T n) |
| | power of by integer exponent n
|
| |
|
template<typename T > |
| void | swap (T &a, T &b) |
| | swap two numbers
|
| |
|
template<typename T > |
| std::string | repr (T &x) |
| | return the usual base-10 representation of a number
|
| |
| template<typename T > |
| int | digit (T x, const int p) |
| | extract a 10-decimal digit form a number: More...
|
| |
|
void | copyBytes (void *dest, const void *src, const unsigned cnt) |
| | copy bytes
|
| |
| unsigned int | count_bits (uint32_t v) |
| | number of '1' bits in a 32-bits integer (Charlie Gordon & Don Clugston) More...
|
| |
| template<typename T > |
| unsigned int | count_bits2 (T v) |
| | number of '1' bits, from: http://graphics.stanford.edu/~seander/bithacks.html More...
|
| |
| unsigned int sMath::count_bits |
( |
uint32_t |
v | ) |
|
|
inline |
Should use Intel SIMD instruction POPCNT
| unsigned int sMath::count_bits2 |
( |
T |
v | ) |
|
| int sMath::digit |
( |
T |
x, |
|
|
const int |
p |
|
) |
| |
|
inline |
1st digit is really the first one, we do not start at zero